<?php
	header("Content-type: text/html; charset=utf-8"); 
	session_start();
	
	if(isset($_POST["Submit"]) && $_POST["Submit"] == "登录")
	{
		$user = $_POST["username"];
		$psw = $_POST["password"];
		if($user == "" || $psw == "")
		{
			echo "<script>alert('请输入用户名或密码！'); history.go(-1);</script>";
		}
		else
		{
			if(!mysql_connect("localhost","root",""))
			{
				echo "<script>alert('数据库连接失败！'); </script>";
			}
			else{
			mysql_select_db("lab");
			//mysql_query("set names 'gbk'");
			$sql = "select ID, password from personalInfo where ID = '".$_POST["username"]."' and password = '".$_POST["password"]."'";
			$result = mysql_query($sql);
			$num = mysql_num_rows($result);
			//echo $sql."<br />".$num."<br />";
			if($num)
			{
				$row = mysql_fetch_array($result);	//将数据以索引方式储存在数组中
				//echo $row[0];
				//session_start();
				$_SESSION['user'] = $row[0];
				//echo $_SERVER['HTTP_HOST']."<br />";
				//echo $_SESSION['userurl'];
				//echo "<script>alert(".$_SESSION['userurl'].");</script>";
				echo "<script>location.href=\"".$_SESSION['userurl']."\";</script>"; 
			}
			else
			{
				echo "<script>alert('用户名或密码不正确！');history.go(-1);</script>";
			}}
		}
	}
	else
	{
		echo "<script>alert('用户名密码提交未成功！'); history.go(-1);</script>";
	}

?>